<h2>Coding Standards</h2>

<p>This page describes the PyroCMS coding standards that all developers (core or module) should adhere to.</p>

<h3>File Format</h3>
<p>All files should be in <span class="caps">UTF</span>-8 format <em><span class="caps">WITHOUT</span></em> the <span class="caps">BOM</span>.  You should always use Unix style line endings (LF).  You can set Git to auto-fix the line endings.</p>
<p><a href="http://help.github.com/dealing-with-lineendings/" target="_blank">Click here for more information</a></p>

<h3>Tabs</h3>
<p>All tabs should be real tabs, not spaces (a.k.a. “soft-tabs”).  This allows each developer to choose his/her own tab size.</p>
<h3>Code Indentation</h3>
<p>Use Allman style indenting. With the exception of Class declarations, braces are always placed on a line by themselves, and indented at the same level as the control statement that “owns” them.</p>
<p><strong>Correct</strong></p>
<pre><code>class Module_name {
    public function method_name()
    {
        foreach($array as $item)
        {
            // Code here
        }
    }
}</code></pre>
<p><strong>In-Correct</strong></p>
<pre><code>class Module_name {
    public function method_name() {
        foreach($array as $item) {
            // Code here
        }
    }
}</code></pre>
<h3>

<span class="caps">PHP</span> Closing Tag</h3>
<p>The closing tag at the end of a file should always be <em>omitted</em>.  This ensures that no accidental output is sent before you want it to be.</p>
<p>Instead, mark the end of the file using the following comment style:</p>
<pre><code>/* End of file filename.php */</code></pre>
<h3>Visibility</h3>
<p>Always use visibility declarations on all class methods and variables.</p>
<p><strong>Correct</strong></p>

<pre><code>class Module_name {
    public $property;
    protected $other_property;
    private $_ci;

    public function method_name()
    {
    }
}</code></pre>
<p><strong>In-Correct</strong></p>
<pre><code>class Module_name {
    var $property;
    var $other_property;
    var $_ci;

    function method_name()
    {
    }
}</code></pre>
<h3>Class and Method Naming</h3>
<p>Class names should always have their first letter uppercase. Use the <span class="caps">PHP</span> 5 __construct() function for constructors unless absolutely necessary.  Multiple words should be separated with an underscore, and not CamelCased. All other class methods should be entirely lowercased and named to clearly indicate their function.</p>
<p><strong>Example</strong></p>
<pre><code>class Module_name {
    public function __construct()
    {
        // Construct Logic
    }

    public function method_name()
    {
        // Method Logic
    }
}</code></pre>

<h3>Variable Naming</h3>
<p>All variable names should describe what they are without being overly verbose.  They should be only contain letters, numbers and underscores (no CamelCase).</p>
<p>All <em>private</em> variables within a class should have their name begin with an underscore.  This helps reduce confusion later in the code.</p>
<p><strong>Correct</strong></p>
<pre><code>public $user_name;
public $password;
protected $bio;
private $_password_hash;</code></pre>
<p><strong>In-Correct</strong></p>
<pre><code>public $UserName;  // CamelCased
public $this_users_password;  // Too verbose
protected $b;  // Not Descriptive
private $password_hash;  // Missing the first underscore</code></pre>